<?php
class StunotifyController extends Controller{
	     
		 
          public function accessRules()
		 {
			return array(
				array(
					'allow',  // allow all users to access 'index' and 'view' actions.
					'expression'=>'$user->rights == 1',
				),
				array(
					'deny',  // deny all users
					'users'=>array('*'),
					'message'=>'You do not have access to this page ! ! ',
				),
			);
		 } 
	public function actionPersonal(){
		 $ci = new CDbCriteria;
		 $ci->addCondition('uId = '.Yii::app()->user->getId());
		 $ci->addCondition('isRead = 0');
		 $total = Stunotification::model()->count($ci);
		 $nos  = Stunotification::model()->findAll($ci);
		$this->render("personal",array('total'=>$total,'nos'=>$nos));
		
	}
	// 返回 stugsp,stuinte,stubasicinfo 信息
	public function actionGetdata(){
		if(Yii::app()->request->isAjaxRequest){
			$metaData = array();
			//1 -- 个人信息 2 -- 综合奖学金 3 -- GSP 4---综合素质 5 -- 学生报名
			$request = Yii::app()->request;
			switch($request->getParam('module')){
				case '1':$metaData = $this->getBasic($request->getParam('id'));break;
				case '2':$metaData = $this->getScholar($request->getParam('id'));break;
				case '3':$metaData = $this->getGsp($request->getParam('id'));break;
				case '4':$metaData = $this->getInte($request->getParam('id'));break;
				case '5':$metaData = $this->getActivity($request->getParam('id'));break;
				
			}
			echo json_encode($metaData);
			
		}else{
			
			$this->redirect('stunotify/personal');
		}
		
	}
	private function getBasic($pk){
		$stuBasic  = Stuinfo::model()->findByPk($pk);
		if($stuBasic){
			return $stuBasic->getShortData();
		}else{
			return false;
			
		}
		
		
	}
	private function getGsp($pk){
		$stuGsp = Stugspitem::model()->findByPk($pk);
		if($stuGsp){
			return $stuGsp->getShortData();
		}else{
			return false;
		}
		
	}
	private function getInte($pk){
		$stuInte = Stuinteitem::model()->findByPk($pk);
		if($stuInte){
			return $stuInte->getShortData();
		}else{
			return false;
		}
		
	}
	private function getScholar($pk){
		$stuSch = Stuscholarship::model()->findByPk($pk);
		if($stuSch){
			return $stuSch->getShortData();
		}else{
			return false;
		}
		
	}
	private function getActivity($pk){
		
		$stuAc = Stuactivity::model()->findByPk($pk);
		if($stuAc){
			
			return $stuAc->getShortData();
		}else{
			
			return false;
		}
		
	}
	public function actionReadone(){
		if(Yii::app()->request->isAjaxRequest){
			$stunotificationId = Yii::app()->request->getParam('id');
			$sn = Stunotification::model()->findByPk($stunotificationId);
			if($sn){
				$sn->isRead = 1;
				if($sn->save()){
					echo json_encode(array('msg'=>'保存成功','code'=>200));
					
				}else{
					$this->logAr($sn);
					echo json_encode(array('msg'=>'保存失败','code'=>501));
				}
			}else{
				echo json_encode(array('msg'=>'没有发现','code'=>404));
				
			}
			
		}else{
			$this->redirect('stunotify/personal');
		}
		
	}
	public function actionPublic(){
		$this->render("public");
		
	}
}